package com.tianci.appstore.ui.detail.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.tianci.appstore.R;
import com.tianci.appstore.ui.SkinManager;
import com.tianci.appstore.ui.util.UICommon;
import com.tianci.appstore.utils.SkyConstants;

public class IntroductionDialog extends Dialog {
    private Context mContext;
    private FrameLayout contentView;
    private ImageView iconImage;
    private TextView titleText;
    private ScrollView scroll;
    private TextView introductionText;

    public IntroductionDialog(Context context) {
        super(context, R.style.full_screen_dlg);
        this.mContext = context;
        getWindow().setLayout(SkyConstants.Div(1920), SkyConstants.Div(1080));
        // TODO Auto-generated constructor stub
        createView();
    }

    private void createView() {
        contentView = new FrameLayout(mContext);
        SkinManager.setBackground(contentView, R.drawable.ui_sdk_app_bg);
        this.setContentView(contentView, new LayoutParams(
                SkyConstants.Div(1920), SkyConstants.Div(1080)));

        scroll = new ScrollView(mContext);
        SkinManager.setBackground(scroll, R.drawable.detail_block_bg);
        scroll.setPadding(SkyConstants.Div(84), SkyConstants.Div(140),
                SkyConstants.Div(60), SkyConstants.Div(84));
        LayoutParams scrollParams = new LayoutParams(SkyConstants.Div(1794),
                SkyConstants.Div(809), Gravity.CENTER);
        scrollParams.setMargins(0, SkyConstants.Div(58), 0, 0);
        contentView.addView(scroll, scrollParams);

        introductionText = UICommon.newTextView(mContext, SkyConstants.Dpi(35), R.color.titleColor);
        introductionText.setSingleLine(false);
        introductionText.setPadding(0, 0, SkyConstants.Div(20), 0);
        introductionText.setLineSpacing(SkyConstants.blockSpacing, 1.0f);
        scroll.addView(introductionText);

        LinearLayout topLayout = new LinearLayout(mContext);
        topLayout.setGravity(Gravity.CENTER_VERTICAL);
        LayoutParams topParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        topParams.setMargins(SkyConstants.Div(144), SkyConstants.Div(148), 0, 0);
        contentView.addView(topLayout, topParams);

        iconImage = new ImageView(mContext);
        iconImage.setScaleType(ScaleType.FIT_XY);
        SkinManager.setBackground(iconImage, R.drawable.icon_default);
        topLayout.addView(iconImage, new LayoutParams(SkyConstants.iconWidth, SkyConstants.iconWidth));

        titleText = UICommon.newTextView(mContext, SkyConstants.Dpi(35), R.color.titleColor);
        SkinManager.setBackground(titleText, R.drawable.title_bg);
        titleText.setGravity(Gravity.CENTER_VERTICAL);
        titleText.setPadding(SkyConstants.Div(36), 0, SkyConstants.Div(39), SkyConstants.Div(9));
        LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, SkyConstants.Div(78));
        titleParams.leftMargin = SkyConstants.Div(24);
        titleParams.topMargin = SkyConstants.Div(7);
        topLayout.addView(titleText, titleParams);
    }

    public void setContent(Bitmap bitmap, String title, String content) {
        if (bitmap != null)
            iconImage.setImageBitmap(bitmap);
        titleText.setText(title);
        introductionText.setText(content);
//        introductionText.setText(         // 用来测试滚动条的
//                "阿卡色粉口了洛杉矶的vs了地级市来得及vad爱的发了放假啊i额无法擦拭的十多个而过坏" + 
//                "按时地方v啊女警id居然发V大看v啊考得好v杜如晦啊看了吗惭愧嘛是多么 哦热狗突然阸而" +
//                "求偶俄日u它分成肯德基覅偶尔啊v阿里会计师都擦垃圾额 出口局阿尔法额放假啊而非奥拉" +
//                "俺记得额察觉二级率案件的软件方腊时让大家v开好刀ui长v会自动就疯狂了热加工费软件给" +
//                "擦开始的话费卡俄节日费假的拒绝啦积德累仁发i家风擦拭的疗法lor高or咯就v困扰是底层" +
//                "才偶尔就安静菜码儿进覅今儿个金额哦人家啊啊金额富婆啊额我恐怕非Ｖ字，们买电脑　Ｖ字" +
//                "阿卡色粉口了洛杉矶的vs了地级市来得及vad爱的发了放假啊i额无法擦拭的十多个而过坏" + 
//                "按时地方v啊女警id居然发V大看v啊考得好v杜如晦啊看了吗惭愧嘛是多么 哦热狗突然阸而" +
//                "求偶俄日u它分成肯德基覅偶尔啊v阿里会计师都擦垃圾额 出口局阿尔法额放假啊而非奥拉" +
//                "俺记得额察觉二级率案件的软件方腊时让大家v开好刀ui长v会自动就疯狂了热加工费软件给" +
//                "擦开始的话费卡俄节日费假的拒绝啦积德累仁发i家风擦拭的疗法lor高or咯就v困扰是底层" +
//                "才偶尔就安静菜码儿进覅今儿个金额哦人家啊啊金额富婆啊额我恐怕非Ｖ字，们买电脑　Ｖ字" +
//                "阿卡色粉口了洛杉矶的vs了地级市来得及vad爱的发了放假啊i额无法擦拭的十多个而过坏" + 
//                "按时地方v啊女警id居然发V大看v啊考得好v杜如晦啊看了吗惭愧嘛是多么 哦热狗突然阸而" +
//                "求偶俄日u它分成肯德基覅偶尔啊v阿里会计师都擦垃圾额 出口局阿尔法额放假啊而非奥拉" +
//                "俺记得额察觉二级率案件的软件方腊时让大家v开好刀ui长v会自动就疯狂了热加工费软件给" +
//                "擦开始的话费卡俄节日费假的拒绝啦积德累仁发i家风擦拭的疗法lor高or咯就v困扰是底层" +
//                "才偶尔就安静菜码儿进覅今儿个金额哦人家啊啊金额富婆啊额我恐怕非Ｖ字，们买电脑　Ｖ字" +
//                "阿卡色粉口了洛杉矶的vs了地级市来得及vad爱的发了放假啊i额无法擦拭的十多个而过坏" + 
//                "按时地方v啊女警id居然发V大看v啊考得好v杜如晦啊看了吗惭愧嘛是多么 哦热狗突然阸而" +
//                "求偶俄日u它分成肯德基覅偶尔啊v阿里会计师都擦垃圾额 出口局阿尔法额放假啊而非奥拉" +
//                "俺记得额察觉二级率案件的软件方腊时让大家v开好刀ui长v会自动就疯狂了热加工费软件给" +
//                "擦开始的话费卡俄节日费假的拒绝啦积德累仁发i家风擦拭的疗法lor高or咯就v困扰是底层" +
//                "才偶尔就安静菜码儿进覅今儿个金额哦人家啊啊金额富婆啊额我恐怕非Ｖ字，们买电脑　Ｖ字" +
//                "阿卡色粉口了洛杉矶的vs了地级市来得及vad爱的发了放假啊i额无法擦拭的十多个而过坏" + 
//                "按时地方v啊女警id居然发V大看v啊考得好v杜如晦啊看了吗惭愧嘛是多么 哦热狗突然阸而" +
//                "求偶俄日u它分成肯德基覅偶尔啊v阿里会计师都擦垃圾额 出口局阿尔法额放假啊而非奥拉" +
//                "俺记得额察觉二级率案件的软件方腊时让大家v开好刀ui长v会自动就疯狂了热加工费软件给" +
//                "擦开始的话费卡俄节日费假的拒绝啦积德累仁发i家风擦拭的疗法lor高or咯就v困扰是底层" +
//                "才偶尔就安静菜码儿进覅今儿个金额哦人家啊啊金额富婆啊额我恐怕非Ｖ字，们买电脑　Ｖ字");
    }

    public void setImageIcon(Bitmap bm) {
        iconImage.setImageBitmap(bm);
    }
}
